home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / What's New? / Software Development Kits / Mac OS USB DDK / MacOS USB DDK 1.0b4 / NeptuneDDK / Examples / SerialBox / ShimSerialEntry.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-26  |  4.8 KB  |  189 lines  |  [TEXT/MPCC]

  1. /*
  2.     File:        ShimSerialEntry.c
  3.  
  4.     Contains:    PC Card Serial Driver.
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1995-1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include "PCCardSerialInternal.h"
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23. //////////////////////////////////////////////////////////////////////////////////////
  24. //
  25. //    TheDriverDescription
  26. //
  27.  
  28. enum
  29. {
  30.     kWabbitDriverVersionMajor    = 0x01,
  31.     kWabbitDriverVersionMinor    = 0x11,
  32.     kWabbitDriverVersionStage    = finalStage,
  33.     kWabbitDriverVersionBuild    = 0
  34. };
  35.  
  36.  
  37. DriverDescription TheDriverDescription = {
  38.     kTheDescriptionSignature,                                    /* OSType driverDescSignature            */
  39.     kInitialDriverDescriptor,                                    /* DriverDescVersion driverDescVersion    */
  40.  
  41.     {
  42.         "\ppccard-serial",                                        /* Name of UART hardware                */
  43.         kWabbitDriverVersionMajor, kWabbitDriverVersionMinor,    /* NumVersion version                    */
  44.         kWabbitDriverVersionStage, kWabbitDriverVersionBuild
  45.     },
  46.     
  47.     {
  48.         kDriverIsLoadedUponDiscovery | kDriverIsOpenedUponLoad,    /* load & open when we’re found            */
  49.         "\p.Wabbit",                                            /* Str31 driverName    (OpenDriver param)    */
  50.         0, 0, 0, 0, 0, 0, 0, 0,                                    /* UInt32 driverDescReserved[8]            */
  51.     },
  52.     
  53.     {
  54.         1,                                                        /*     ServiceCount nServices                */
  55.         {
  56.             kServiceCategoryNdrvDriver,                            /* OSType serviceCategory                */
  57.             kNdrvTypeIsGeneric,                                    /* OSType serviceType                    */
  58.             1, 0, 0, 0                                            /* NumVersion serviceVersion            */
  59.         }
  60.     }
  61. };
  62.  
  63.  
  64.  
  65.  
  66.  
  67. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  68.  * DoDriverIO
  69.  */
  70.  
  71. OSStatus
  72. DoDriverIO(    AddressSpaceID        spaceID,
  73.             IOCommandID            ioCommandID,
  74.             IOCommandContents    ioCommandContents,
  75.             IOCommandCode        ioCommandCode,
  76.             IOCommandKind        ioCommandKind)
  77. {
  78.     OSStatus    status = noErr;
  79.  
  80. #pragma unused (spaceID)
  81.  
  82.     /*
  83.      * Note: Initialize, Open, KillIO, Close, and Finalize are either synchronous
  84.      * or immediate. Read, Write, Control, and Status may be immediate,
  85.      * synchronous, or asynchronous.
  86.      *
  87.      * Note 2:  As described in the theory of operation the read and write
  88.      * commands will be handled by the ".In" and ".Out" drivers that the ndrv
  89.      * installed in the Unit Table.
  90.      */
  91.     switch (ioCommandCode)
  92.     {
  93.         //    I/O Commands:
  94.  
  95.         case kReadCommand:
  96.             status = DoRead(ioCommandID,(IOParam *) ioCommandContents.pb);
  97.             break;
  98.             
  99.         case kWriteCommand:
  100.             status = DoWrite(ioCommandID,(IOParam *) ioCommandContents.pb);
  101.             break;
  102.  
  103.         case kKillIOCommand:
  104.             status = DoKillIO(ioCommandID,(IOParam *) ioCommandContents.pb);
  105.             break;
  106.  
  107.  
  108.         //    Control/Configuration Commands:
  109.  
  110.         case kControlCommand:
  111.             status = DoControl((CntrlParam *) ioCommandContents.pb);
  112.             break;
  113.  
  114.         case kStatusCommand:
  115. //        DriverGestalt doesn't do anything so in the interest of getting this thing building
  116. //        as part of Tomahawk I'll just comment it out for now because Excelsior's MasterInterfaces
  117. //        don't include DriverGestalt.h (need to get this done later).
  118. //            if (((CntrlParam *) ioCommandContents.pb)->csCode == kDriverGestaltCode)
  119. //                status = DoDriverGestalt((CntrlParam *) ioCommandContents.pb);
  120. //            else
  121.             status = DoStatus((CntrlParam *) ioCommandContents.pb);
  122.             break;
  123.  
  124.  
  125.         //    Initialize/Finalize Commands:
  126.  
  127.         case kInitializeCommand:            /* Initialize                        */
  128.         case kReplaceCommand:                /* or replace an old driver            */
  129.             status = DoInitialization(    ioCommandContents.initialInfo->refNum,
  130.                                         &ioCommandContents.initialInfo->deviceEntry,
  131.                                         (ioCommandCode == kReplaceCommand));
  132.             break;
  133.  
  134.         case kFinalizeCommand:                /* Finalize                            */
  135.         case kSupersededCommand:            /* or get ready to be replaced        */
  136.             status = DoFinalization(    ioCommandContents.initialInfo->refNum,
  137.                                         &ioCommandContents.initialInfo->deviceEntry,
  138.                                         (ioCommandCode == kSupersededCommand));
  139.             break;
  140.  
  141.         case kOpenCommand:
  142.             status = DoOpen(ioCommandContents.pb);
  143.             break;
  144.  
  145.         case kCloseCommand:
  146.             status = DoClose(ioCommandContents.pb);
  147.             break;
  148.  
  149.         default:
  150.             status = paramErr;
  151.             break;
  152.     }
  153.  
  154.     /*
  155.      * Force a valid result for immediate commands -- they must return a valid
  156.      * status to the Driver Manager: returning kIOBusyStatus would be a bug.
  157.      *
  158.      * Non-immediate commands return a status from the lower-level routine. If the
  159.      * status is kIOBusyStatus, we just return -- an asynchronous I/O completion
  160.      * routine will eventually complete the request. If it's some other status, the
  161.      * lower-level routine has completed a non-immediate task, so we call
  162.      * IOCommandIsComplete and return its (presumably noErr) status.
  163.      */
  164.          
  165.     if (ioCommandKind == kImmediateIOCommandKind)
  166.     {
  167.         /* Immediate commands return the operation status        */
  168.     }
  169.     
  170.     else if (status == 1)
  171.     {
  172.         /*
  173.          * An asynchronous operation is in progress. The driver handler promises
  174.          * to call IOCommandIsComplete when the operation concludes.
  175.          */
  176.         status = noErr;
  177.     }
  178.     else
  179.     {
  180.         /*
  181.          * Normal command that completed synchronously. Dequeue the user's
  182.          * parameter block.
  183.          */
  184.         status = IOCommandIsComplete(ioCommandID, status);
  185.     }
  186.  
  187.     return status;
  188. }
  189.